package com.kui.demo.repeatsubmit;

import org.springframework.util.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class RequestUtil {

    public static Long getRequestUserId(HttpServletRequest request) {
        String uid = request.getHeader("uid");
        if (!StringUtils.isEmpty(uid)) {
            return Long.valueOf(uid);
        }
        return null;
    }

    public static Long getRequestUserId() {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        return getRequestUserId(request);
    }
}
